package assignment2;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**
 * @DESCRIPATION java 8 的优雅聊天
 * @AUTHOR 戴超
 * @DATE 2018/6/19
 **/
public class Server {
    public static void main(String[] args) throws Exception {
        ServerSocket ss = new ServerSocket(8888);
        System.out.println("启动服务器!");
        // 设置超时
        ss.setSoTimeout(15 * 1000);
        Socket s = ss.accept();
        System.out.println("客户端:" + s.getInetAddress() + "已连接到服务器");
        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
        new Thread(new Receiver(br, s)).start();
        new Thread(new Sender(bw, s)).start();
    }
}
